package com.rdc.qingkou.utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.rdc.qingkou.Application.MyApplication;
import com.rdc.qingkou.entity.User;

/**
 * Created by Lin Yaotian on 2018/4/19.
 */

public class UserUtil {

    /**
     * 保存 User 信息
     *
     * @param user
     */
    public static void saveUser(User user) {
        SharedPreferences.Editor editor =
                MyApplication.getContext().getSharedPreferences("userInfo", Context.MODE_PRIVATE).edit();
        editor.putString("telNumber", user.getTelNumber());
        editor.putInt("userId", user.getUserId());
        editor.putString("nickName", user.getNickName());
        editor.putString("imageUrl", user.getImageUrl());
        editor.putInt("sex", user.getSex());
        editor.putString("signature", user.getSignature());
        editor.apply();
    }

    /**
     * 获取 User 信息
     *
     * @return
     */
    public static User getCurrentUser() {
        User user = new User();
        SharedPreferences sp =
                MyApplication.getContext().getSharedPreferences("userInfo", Context.MODE_PRIVATE);
        user.setNickName(sp.getString("nickName", ""));
        user.setImageUrl(sp.getString("imageUrl", ""));
        user.setUserId(sp.getInt("userId", 0));
        user.setTelNumber(sp.getString("telNumber", ""));
        user.setSignature(sp.getString("signature", ""));
        user.setSex(sp.getInt("sex", 0));
        return user;
    }
}
